package com.zzyl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;


@SpringBootTest
public class HuToolTestt {

    @Test
    public void test(){
        String s = HttpUtil.get("https://www.jd.com/");
        System.out.println(s);
    }

    @Test
    public void test2(){
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("pageNum",1);
        paramMap.put("pageSize",10);
        HttpResponse response = HttpUtil.createRequest(Method.GET, "http://localhost:8080/serve/project/list")
                .header("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFmMmM5NDg3LTJiNWItNDMxMC04YzA4LTdlMzRhMTkzMWUyYiJ9.puz4MG7xNloefqT27nkhRPzTn_fqclWQAln1LgvBNh3Y6HtrZK8cStu7AhaqZ0yCmHSnAu5KyUMHvJ1zvxRBkg")
                .form(paramMap)
                .execute();
        if ( response.isOk()){
            String body = response.body();
            System.out.println(body);
        }
    }

    @Test
    public void testWeater() {
        String url = "https://aliv18.data.moji.com/whapi/json/alicityweather/forecast24hours";
        String appcode = "453c3f4ba28045a78e553fae81cb6395";//修改成自己的appcode
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("cityId", "2");

        HttpResponse response = HttpUtil.createRequest(Method.POST, url)
                .header("Authorization", "APPCODE " + appcode)
                .form(param)
                .execute();
        if (response.getStatus() == 200) {
            System.out.println(response.body());
        }

    }
}
